/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Connect.ConnectionJDBC;
import DatabasePOJO.sanpham;
import java.sql.Date;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Mr-Nguyen
 */
public class sanphamDAO {
    public static ArrayList<sanpham> getListSanPham(String malv)
    {
        ArrayList<sanpham> arr = new ArrayList<sanpham>();
        ConnectionJDBC cnn = new ConnectionJDBC();
        cnn.Connect();
        try{
            String sql = "select * from sanpham " + malv;
            ResultSet rs = cnn.getTable(sql);
            while(rs.next())
            {
                sanpham sp = new sanpham();
                sp.setDiemNoiBat(rs.getString("DiemNoiBat"));
                sp.setDieuKienApDung(rs.getString("DieukienApDung"));
                sp.setGiaBan(rs.getString("GiaBan"));
                sp.setGiaKhuyenMai(rs.getString("GiaKhuyenMai"));
                sp.setHinhDaiDien(rs.getString("HinhDaiDien"));
                sp.setMaChiTiet(rs.getString("MaChiTiet"));
                sp.setLuotMua(rs.getString("LuotMua"));
                sp.setMaCuaHang(rs.getString("MaCuaHang"));
                sp.setMaLinhVuc(rs.getString("MaLinhVuc"));
                sp.setMaSanPham(rs.getString("MaSanPham"));
                Date d = rs.getDate("NgayHetHang");
                sp.setNgayHetHang(d.toString());
                sp.setTitle(rs.getString("Title"));
                arr.add(sp);
            }
        }catch(Exception ex){
            
        }
        finally{
            cnn.Close();
            return arr;
        }
    }
    public static sanpham getSanPham(String ma)
    {
        sanpham sp = new sanpham();
        ConnectionJDBC cnn = new ConnectionJDBC();
        cnn.Connect();
        try{
            String sql = "select * from sanpham where MaSanPham=" + ma;
            ResultSet rs = cnn.getTable(sql);
            while(rs.next())
            {
                sp.setDiemNoiBat(rs.getString("DiemNoiBat"));
                sp.setDieuKienApDung(rs.getString("DieukienApDung"));
                sp.setGiaBan(rs.getString("GiaBan"));
                sp.setGiaKhuyenMai(rs.getString("GiaKhuyenMai"));
                sp.setHinhDaiDien(rs.getString("HinhDaiDien"));
                sp.setMaChiTiet(rs.getString("MaChiTiet"));
                sp.setLuotMua(rs.getString("LuotMua"));
                sp.setMaCuaHang(rs.getString("MaCuaHang"));
                sp.setMaLinhVuc(rs.getString("MaLinhVuc"));
                sp.setMaSanPham(rs.getString("MaSanPham"));
                Date d = rs.getDate("NgayHetHang");
                sp.setNgayHetHang(d.toString());
                sp.setTitle(rs.getString("Title"));
          }
            sql = "select chitiet from chitietsanpham where machitietsanpham = " + sp.getMaChiTiet();
            rs = cnn.getTable(sql);
            rs.next();
            String ct = rs.getString("chitiet");
            sp.setMaChiTiet(ct);
        }catch(Exception ex){
            
        }
        finally{
            cnn.Close();
            return sp;
        }

    }
}
